package com.lmh.system.utils;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

/**
 * BCrypt对密码进行加密
 */
public class BCryptUtils {
    /**
     * 加密操作
     * @param password
     * @return
     */
    public static String encryptPassword(String password) {
        BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
        return passwordEncoder.encode(password);
    }

    /**
     * 判断用户输入的密码和数据库中存储的密码是否相同
     * @param rawPassword
     * @param encodedPassword
     * @return
     */
    public static boolean matchesPassword(String rawPassword,String encodedPassword) {
        BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
        return passwordEncoder.matches(rawPassword,encodedPassword);
    }

    public static void main(String[] args) {
        System.out.println(BCryptUtils.matchesPassword("Admin@123","$2a$10$A9JKTZb/KIeJjmdlK3VTiOS5a8mQWub2B3z6UCBdBzE3TZnJZWiE6"));
    }
}
